'use strict';
const { globalShortcut } = require('electron');
const { logger } = require('ee-core/log');
const { getMainWindow } = require("ee-core/electron");
const { WebContentsView, ipcMain, Menu } = require('electron/main');
const { configService } = require('../service/config');
// const { ticketService } = require('../service/ticket');
const path = require('path');
const { dialog } = require('electron');
// const homeUrl = "https://fdszh_0000221_pre2.hieap.cn/fdszh/login/login/func/login.func";
// const loginUrl = "https://sso.fdauto.com/ssoAuth/logout?service=https://fdszh_0000221_pre2.hieap.cn/fdszh/login/login/func/login.func";
/**
 * 示例服务
 * @class
 */
class HomeService {

    ssoHost = configService.get('ssoHost');
    eap5Host = configService.get('eap5Host');
    tabHeight = 75;//标签页高度
    width = 1400;
    height = 900;
    tabs = [];
    activeTabId = null;
    dragPos = null;
    async getLoginUrl() {
        let env = process.env;
        if (env.NODE_ENV == "dev")
            this.eap5Host = "https://fdszh_0000221_pre2.hieap.cn"
        return this.eap5Host + "/fdszh/login/login/func/login.func?pn=fdszh/0000221";
    }

    async open(homeUrl) {
        this.tabs = [];
        this.win = getMainWindow();
        // this.win.openDevTools();
        this.win.setSize(this.width, this.height);//调整窗口的width和 height. 
        this.win.setResizable(true);//设置用户是否可以手动调整窗口大小。
        this.win.setMaximizable(true);
        this.win.center();//将窗口移动到屏幕中央。
        // 监听窗口大小变化
        this.win.on('resize', () => { this.updateViewLayout() });
        this.createTab(homeUrl, true, true, true);
        try {
            this.removeIpcListeners();
        } catch (error) {
            logger.error(error);
        }
        this.ipcMainEvents();
        // 注册全局快捷键
        // this.registerShortcuts();//影响系统快捷键
    }

    // 添加注册快捷键的方法
    registerShortcuts() {
        const me = this;
        // 注册F5
        const f5Shortcut = process.platform === 'darwin' ? 'F5' : 'F5';
        // const nextTabShortcut = process.platform === 'darwin' ? 'Cmd+Tab' : 'Ctrl+Tab';?
        globalShortcut.register(f5Shortcut, () => {
            me.refreshTab();
        });

    }
    handleTabContextMenu(tabId) {
        const tabIndex = this.tabs.findIndex(t => t.id === tabId);
        let curtab = this.tabs.find(t => t.id === tabId);
        const showCLose = this.tabs.length > 1 && !curtab.hideclose;

        const menus = [
            {
                label: '重新加载',
                click: () => {
                    this.refreshTab();
                }
            },
            { type: 'separator' },
            {
                label: '关闭标签页',
                enabled: showCLose,
                click: () => {
                    this.closeTab(tabId);
                }
            },
            {
                label: '关闭其他标签页',
                enabled: this.tabs.length > 1,
                click: () => {
                    this.tabs.filter(t => t.id !== tabId).forEach(t => {
                        this.closeTab(t.id);
                    });
                }
            },
            {
                label: '关闭右侧标签页',
                enabled: tabIndex < this.tabs.length - 1,
                click: () => {
                    this.tabs.slice(tabIndex + 1).forEach(t => {
                        this.closeTab(t.id);
                    });
                }
            },
            {
                label: '关闭左侧标签页',
                enabled: tabIndex > 0,
                click: () => {
                    this.tabs.slice(0, tabIndex).forEach(t => {
                        this.closeTab(t.id);
                    });
                }
            }
        ];

        const menu = Menu.buildFromTemplate(menus);
        // 更明确的 popup 调用
        menu.popup({
            window: this.win,
            callback: () => {
                // console.log('Menu closed');
            }
        });
    }
    async getTabs() {
        return this.tabs.map(tab => ({
            id: tab.id,
            title: tab.title,
            url: tab.url,
            hideclose: tab.hideclose,
            isActive: tab.id === this.activeTabId
        }))
    }
    // 切换到下一个标签页
    switchToNextTab() {
        if (this.tabs.length <= 1) return;

        const currentIndex = this.tabs.findIndex(tab => tab.id === this.activeTabId);
        if (currentIndex === -1) return;

        const prevIndex = (currentIndex - 1 + this.tabs.length) % this.tabs.length;
        const prevTab = this.tabs[prevIndex];

        if (prevTab) {
            this.setActiveTab(prevTab.id);
        }
    }

    // 切换到上一个标签页
    switchToPrevTab() {
        if (this.tabs.length <= 1) return;

        const currentIndex = this.tabs.findIndex(tab => tab.id === this.activeTabId);
        if (currentIndex === -1) return;

        const nextIndex = (currentIndex + 1) % this.tabs.length;
        const nextTab = this.tabs[nextIndex];

        if (nextTab) {
            this.setActiveTab(nextTab.id);
        }
    }
    ipcMainEvents() {
        var me = this;
        // 保存事件处理函数的引用
        this.handleCreateTab = (event, url) => {
            me.createTab(url)
        };

        this.handleActivateTab = (event, tabId) => {
            me.setActiveTab(tabId)
        };

        this.handleCloseTab = (event, tabId) => {
            me.closeTab(tabId);
        };

        this.handleRefreshTab = (event) => {
            me.refreshTab();
        };

        this.handleGoBack = (event) => {
            me.goBack();
        };

        this.handleGoForward = (event) => {
            me.goForward();
        };
        this.handleminimizeWindow = (event) => {
            me.win.minimize();
        }
        this.handlemaximizeWindow = (event) => {
            if (me.win.isMaximized()) {
                me.win.unmaximize();
            } else {
                me.win.maximize();
            }
        }
        this.handleCloseWindow = (event, tabId) => {
            me.win.close();
        };

        this.handleShowTabContextMenu = (event, tabId) => {
            me.handleTabContextMenu(tabId);
        };

        this.handleSwitchToNextTab = (event) => {
            me.switchToNextTab();
        };

        this.handleSwitchToPrevTab = (event) => {
            me.switchToPrevTab();
        };

        // 在 ipcMainEvents 方法中添加
        this.handleLoadUrl = (event, url) => {
            me.loadUrl(url);
        };

        ipcMain.on('create-tab', this.handleCreateTab);
        ipcMain.on('activate-tab', this.handleActivateTab);
        ipcMain.on('close-tab', this.handleCloseTab);
        ipcMain.on('refresh-tab', this.handleRefreshTab);
        ipcMain.on('go-back', this.handleGoBack);
        ipcMain.on('go-forward', this.handleGoForward);
        ipcMain.on('minimize-window', this.handleminimizeWindow)
        ipcMain.on('maximize-window', this.handlemaximizeWindow);
        ipcMain.on('close-window', this.handleCloseWindow);
        ipcMain.on('show-tab-context-menu', this.handleShowTabContextMenu);

        ipcMain.on('switch-to-next-tab', this.handleSwitchToNextTab);
        ipcMain.on('switch-to-prev-tab', this.handleSwitchToPrevTab);

        ipcMain.on('load-url', this.handleLoadUrl);
        // 添加窗口状态检查处理程序

        ipcMain.handle('is-maximized', async () => {
            return me.win.isMaximized();
        });
        ipcMain.on("win-drag-start", (x, y) => {
            me.dragPos = me.win.getPosition();
            // console.log("win-drag-start:", me.dragPos[0], "--------", me.dragPos[1]);
        })
        // 使用系统级鼠标事件监听
        ipcMain.on('win-dragging', (event, deltaX, deltaY, deltaX1, deltaY1) => {
            if (me.win && !me.win.isMaximized()) {
                try {
                    const newX = me.dragPos[0] + deltaX;
                    const newY = me.dragPos[1] + deltaY;
                    me.win.setBounds({ x: newX, y: newY });
                    return;
                } catch (error) {
                    console.error('Error during drag:', error);
                }
            }
        });
        ipcMain.on('win-drag-end', (event, deltaX, deltaY) => {
            // const [x, y] = me.win.getPosition();
            // me.win.setPosition(x + deltaX, y + deltaY);
        });

        ipcMain.handle('get-tabs', () => {
            return this.tabs.map(tab => ({
                id: tab.id,
                title: tab.title,
                url: tab.url,
                close: tab.close,
                isActive: tab.id === activeTabId
            }))
        })
        // 添加 IPC 处理程序来获取 POST 数据
        ipcMain.handle('get-post-data', (event, postDataId) => {
            if (global.postDataStorage && global.postDataStorage.has(postDataId)) {
                const postData = global.postDataStorage.get(postDataId);
                global.postDataStorage.delete(postDataId);
                return postData;
            }
            return null;
        });
        ipcMain.handle('login', (event, username) => {
            return username;
        });
    }
    removeIpcListeners() {
        ipcMain.removeListener('create-tab', this.handleCreateTab);
        ipcMain.removeListener('activate-tab', this.handleActivateTab);
        ipcMain.removeListener('close-tab', this.handleCloseTab);
        ipcMain.removeListener('refresh-tab', this.handleRefreshTab);
        ipcMain.removeListener('go-back', this.handleGoBack);
        ipcMain.removeListener('go-forward', this.handleGoForward);
        ipcMain.removeListener('minimize-window', this.handleminimizeWindow);
        ipcMain.removeListener('maximize-window', this.handlemaximizeWindow);
        ipcMain.removeListener('close-window', this.handleCloseWindow);
        ipcMain.removeListener('show-tab-context-menu', this.handleShowTabContextMenu);

        ipcMain.removeListener('switch-to-next-tab', this.handleSwitchToNextTab);
        ipcMain.removeListener('switch-to-prev-tab', this.handleSwitchToPrevTab);
    }

    // 添加 loadUrl 方法
    loadUrl(url) {
        const activeTab = this.tabs.find(tab => tab.id === this.activeTabId);
        if (activeTab) {
            // 可能需要验证 URL 格式
            try {
                new URL(url);
            } catch (error) {
                console.error('Invalid URL:', error);
                return;
            }
            activeTab.view.webContents.loadURL(url);
        }
    }
    createTab(url = 'https://baidu.com', isActive = true, isInit = false, hideclose, hidetab) {
        const view = new WebContentsView({
            webPreferences: {
                preload: path.join(__dirname, '..', 'preload', 'bridge.js'),
                partition: 'persist:main', // 使用持久化 session
                // 确保安全设置与浏览器一致
                webSecurity: true,
                allowRunningInsecureContent: false
            }
        });
        this.win.contentView.addChildView(view);
        const tabId = Date.now() + Math.random()
        const tab = {
            id: tabId,
            view: view,
            url: url,
            hideclose: hideclose,
            title: '新标签页加载中...',
            loading: false // 添加加载状态
        }
        if (!hidetab) {
            this.tabs.push(tab);

        }
        // 使用更新后的布局函数设置视图位置
        this.updateViewLayout();
        const [windowWidth, windowHeight] = this.win.getContentSize();
        // 设置视图位置（为标签页留出空间）
        !hidetab && view.setBounds({
            x: 0,
            y: this.tabHeight,
            width: windowWidth,
            height: windowHeight - this.tabHeight
        })
        // view.webContents.openDevTools();
        // view.webContents.session.webRequest.onBeforeSendHeaders((details, callback) => {
        // console.log('发送请求头:', details.requestHeaders);
        // callback({ requestHeaders: details.requestHeaders });
        // });
        // 替换现有的 did-get-response-details 监听器
        // view.webContents.session.webRequest.onHeadersReceived((details, callback) => {
        // console.log('=== 捕获到响应头 ===');
        // console.log('请求URL:', details.url);
        // console.log('HTTP状态码:', details.statusCode);
        // console.log('响应头信息:', JSON.stringify(details.responseHeaders, null, 2));
        // 检查是否有 Set-Cookie 头
        // if (details.responseHeaders['set-cookie'] || details.responseHeaders['Set-Cookie']) {
        //     console.log('Set-Cookie 头:', details.responseHeaders['set-cookie'] || details.responseHeaders['Set-Cookie']);
        // }
        // if (details.responseHeaders['location'] || details.responseHeaders['Location']) {
        //     console.log('Location 头:', details.responseHeaders['location'] || details.responseHeaders['Location']);
        // }
        // 如果您需要将这些信息传递给前端
        // this.win.webContents.send('response-headers-received', {
        //     url: details.url,
        //     statusCode: details.statusCode,
        //     headers: details.responseHeaders,
        //     tabId: tab.id
        // });
        // callback({ responseHeaders: details.responseHeaders });
        // });

        // 监听响应头
        // view.webContents.on('did-get-response-details', (event, status, newURL, originalURL, httpResponseCode, requestMethod, referrer, headers, resourceType) => {

        // console.log(`URL: ${newURL}`);
        // console.log(`状态码: ${httpResponseCode}`);
        // console.log('响应头:', headers);

        // 可以在这里处理特定的响应头逻辑
        // 例如检查认证相关头信息等
        // });
        view.webContents.loadURL(url);
        // 在 createTab 方法中添加以下代码
        view.webContents.on('will-navigate', (event, url) => {
            // 拦截主框架跳转
            console.log('主框架即将跳转到:', url);
            if (url.startsWith("eap://logout&browser")) {
                // this.win.setSize(672, 430);
                // this.win.setResizable(false);//设置用户是否可以手动调整窗口大小。
                // this.win.setMaximizable(false);
                // this.win.center();//将窗口移动到屏幕中央。
                // this.win.webContents.send('set-default');
                // this.removeIpcListeners()
                // this.tabs.forEach(tab => {
                //     this.win.contentView.removeChildView(tab.view);
                //     tab.view.webContents.destroy();
                // });
                // this.tabs = [];
                let defaultUrl = `${this.ssoHost}/ssoAuth/logout?service=${this.getLoginUrl()}`
                view.webContents.loadURL(defaultUrl);
            }
            // 根据业务需求决定是否阻止跳转或修改跳转行为
        });


        view.webContents.on('will-prevent-unload', (event) => {
            const choice = dialog.showMessageBoxSync(this.win, {
                type: 'question',
                buttons: ['重新加载', '取消'],
                title: '重新加载此网站?',
                cancelId: 1,//用于取消对话框的按钮的索引
                message: '系统可能不会保存您所做的更改。'
            });
            if (choice === 0) {
                event.preventDefault(); // 允许离开
            }
        });
        // 在 createTab 方法中添加对 beforeunload 的处理
        view.webContents.on('before-unload', (event) => {
            console.log('页面即将卸载');
            // 可以在这里执行清理操作
        });

        view.webContents.on('will-redirect', (event, url) => {
            // 拦截服务器重定向
            console.log('即将重定向到:', url);
            // 可以选择阻止重定向
            // event.preventDefault();
        });

        // 在 createTab 函数中，view.webContents.loadURL(url) 之后添加：
        view.webContents.once('dom-ready', (args) => {
            // 注入处理POST数据的脚本
            view.webContents.executeJavaScript(`
        (function() {
            // 检查URL中是否包含post_data_id参数
            const urlParams = new URLSearchParams(window.location.search);
            const postDataId = urlParams.get('post_data_id');
            if (postDataId) {
                // 通过preload.js中定义的API获取POST数据
                if (window.electron && window.electron.getPostData) {
                    window.electron.getPostData(postDataId).then(postData => {
                        if (postData) {
                            // 重新提交表单
                            resubmitForm(postData);
                        }
                    }).catch(error => {
                        console.error('获取POST数据失败:', error);
                    });
                }
            }
            // 重新提交表单的函数
            async function resubmitForm(postData) {
                try {
                    // 获取原始URL（去除post_data_id参数）
                    const urlObj = new URL(window.location.href);
                    urlObj.searchParams.delete('post_data_id');
                    const urlWithoutParams = urlObj.toString();
                    
                    const response = await fetch(urlWithoutParams, {
                        method: 'POST',
                        headers: {
                            'Content-Type': 'application/x-www-form-urlencoded',
                        },
                        body: postData
                    });
                    
                    if (response.ok) {
                        // 如果有重定向，则跳转到新页面
                        if (response.redirected) {
                            window.location.href = response.url;
                        } else {
                            // 否则替换当前页面内容
                            const html = await response.text();
                            document.open();
                            document.write(html);
                            document.close();
                        }
                    } else {
                        console.error('表单提交失败，状态码:', response.status);
                    }
                } catch (error) {
                    console.error('表单提交错误:', error);
                }
            }
        })();
    `);
        });
        // 监听页面开始加载
        view.webContents.on('did-start-loading', () => {
            tab.loading = true;
            // tab.title = '加载中...';
            this.win.webContents.send('tab-loading-start', {
                id: tab.id,
                title: tab.title,
                loading: tab.loading
            });
        });

        // 监听页面加载完成
        view.webContents.on('did-stop-loading', () => {
            setTimeout(() => {
                tab.loading = false;
                // 获取当前页面的实际标题
                const currentTitle = view.webContents.getTitle();
                tab.title = currentTitle;
                let url = view.webContents.getURL();
                tab.url = url;
                this.win.webContents.send('tab-loading-stop', {
                    id: tab.id,
                    title: currentTitle,
                    url: url,
                    loading: tab.loading
                });
            }, 100);
        });

        // 监听页面标题变化
        view.webContents.on('page-title-updated', (event, title) => {
            tab.title = title;
            tab.loading = false;
            let url = view.webContents.getURL();
            tab.url = url;
            this.win.webContents.send('tab-updated', {
                id: tab.id,
                title: title,
                url: url,
                loading: tab.loading
            })
        })

        // 设置新窗口打开处理
        view.webContents.setWindowOpenHandler((details) => {
            const { url, postBody } = details;

            if (postBody && postBody.data) {
                // 解析表单数据
                let postDataString = '';

                postBody.data.forEach((dataItem, index) => {
                    if (dataItem.bytes) {
                        const dataString = dataItem.bytes.toString('utf8');
                        postDataString += dataString;

                        // 如果有分隔符，添加到字符串中
                        if (index < postBody.data.length - 1) {
                            postDataString += '&';
                        }
                    }
                });

                // 可以将解析后的数据存储或传递
                global.postDataStorage = global.postDataStorage || new Map();
                const dataId = Date.now().toString();
                global.postDataStorage.set(dataId, postDataString);
                // 将数据ID附加到URL
                const separator = url.includes('?') ? '&' : '?';
                const newUrl = `${url}${separator}post_data_id=${dataId}`;
                this.createTab(newUrl);
            } else {
                this.createTab(url, true);
            }

            return { action: 'deny' };
        });

        view.webContents.on('did-fail-load', (event, errorCode, errorDescription, validatedURL, isMainFrame) => {
            console.error(`Failed to load URL: ${validatedURL}`, errorDescription);
            // 只处理主框架的错误（避免iframe等子资源的错误影响）
            if (isMainFrame) {
                // 显示错误页面或友好的错误信息
                const errorScript = `
                (function() {
                    // 清空页面内容
                    document.body.innerHTML = '';
                    
                    // 创建错误提示元素
                    const errorContainer = document.createElement('div');
                    errorContainer.innerHTML = \`
                        <div class="error-container" style="
                        box-sizing: border-box;
                        font-size: 1em;
                        line-height: 1.6em;
                        margin: 14vh auto 0;
                        max-width: 600px;
                        width: 100%;">
                            <h1 class="error-title">无法访问此网站</h1>
                            <p class="error-message"></p><strong>${validatedURL} </strong>拒绝了我们的连接请求。
                            <div>
                                <p>请试试以下办法</p>
                                <ul class="">
                                <li>检查网络连接</li>
                                <li>检查代理服务器和防火墙</li>
                                </ul>
                            </div>
                            <div>${errorDescription}</div>
                            <button class="retry-button" style="
                            background: #007bff; 
                            color: white; 
                            border: none; 
                            padding: 0.5rem 1rem;
                            margin: 10px; 
                            border-radius: 4px; 
                            cursor: pointer; " onclick="location.reload()">重新加载</button>
                        </div>
                    \`;
                    document.body.appendChild(errorContainer);
                })();
                `;

                // 执行错误提示脚本
                view.webContents.executeJavaScript(errorScript);

                // 同时更新标签页信息
                const tab = this.tabs.find(t => t.view === view);
                if (tab) {
                    this.win.webContents.send('tab-updated', {
                        id: tab.id,
                        title: tab.title,
                        url: validatedURL,
                        loading: false
                    });
                }
            }
        });

        // 设置上下文菜单
        this.setupContextMenu(view);

        // 通知渲染进程有新标签页
        if (!isInit && !hidetab)
            this.win.webContents.send('tab-created', {
                id: tab.id,
                title: tab.title,
                url: tab.url,
                isActive: isActive
            })

        if (isActive) {
            this.setActiveTab(tabId)
        }

        return view;

    }
    setupContextMenu(view) {
        var me = this;
        view.webContents.on('context-menu', (event, params) => {
            const menuTemplate = [
                {
                    label: '在新标签页中打开链接',
                    enabled: params.linkURL && params.linkURL !== '',
                    click: () => {
                        if (params.linkURL) {
                            me.createTab(params.linkURL)
                        }
                    }
                },
                { type: 'separator' },
                {
                    label: '后退',
                    enabled: view.webContents.canGoBack(),
                    click: () => view.webContents.goBack()
                },
                {
                    label: '前进',
                    enabled: view.webContents.canGoForward(),
                    click: () => view.webContents.goForward()
                },
                {
                    label: '重新加载',
                    click: () => view.webContents.reload()
                },
                {
                    label: '强制重新加载',
                    click: () => view.webContents.reloadIgnoringCache()
                },
                {
                    label: '复制',
                    accelerator: 'CmdOrCtrl+C',
                    role: 'copy'
                },
                {
                    label: '粘贴',
                    accelerator: 'CmdOrCtrl+V',
                    role: 'paste'
                },
                {
                    label: '查看源代码',
                    click: () => {
                        // 获取当前页面URL
                        const currentUrl = view.webContents.getURL();
                        // 创建查看源代码的URL
                        const viewSourceUrl = 'view-source:' + currentUrl;
                        // 在新标签页中打开
                        me.createTab(viewSourceUrl);
                    }
                }, {
                    label: '开发者工具',
                    click: () => {
                        view.webContents.toggleDevTools()
                    }
                }

            ]
            const menu = Menu.buildFromTemplate(menuTemplate)
            menu.popup();
        })
    }
    // 关闭标签页
    closeTab(tabId) {
        const tabIndex = this.tabs.findIndex(tab => tab.id === tabId)
        if (tabIndex !== -1) {
            const tab = this.tabs[tabIndex];
            if (tab.hideclose) {
                return;
            }
            this.win.contentView.removeChildView(tab.view);
            try {
                tab.view.webContents && tab.view.webContents.destroy();
            } catch (error) {
                console.log(error);
            }

            this.tabs.splice(tabIndex, 1);

            this.win.webContents.send('tab-closed', tabId);

            // 如果关闭的是当前标签页，激活下一个或上一个
            if (tabId === this.activeTabId) {
                if (this.tabs.length > 0) {
                    const nextTab = this.tabs[Math.max(0, tabIndex - 1)];
                    if (nextTab) {
                        this.setActiveTab(nextTab.id);
                    }
                } else {
                    this.activeTabId = null
                }
            }
        }
        // if (this.tabs.length === 0) {
        //     this.createTab(homeUrl);
        // }
    }

    refreshTab() {
        const tabIndex = this.tabs.findIndex(tab => tab.id === this.activeTabId)
        if (tabIndex !== -1) {
            const tab = this.tabs[tabIndex];
            // 在刷新前重置标题
            const currentTitle = tab.view.webContents.getTitle();
            tab.title = currentTitle;
            this.win.webContents.send('tab-updated', {
                id: tab.id,
                title: tab.title,
                url: tab.url,
                loading: true
            });
            tab.view.webContents.reload();
        }
    }

    goBack() {
        const tabIndex = this.tabs.findIndex(tab => tab.id === this.activeTabId)
        if (tabIndex !== -1) {
            const tab = this.tabs[tabIndex];
            if (tab.view.webContents.canGoBack())
                tab.view.webContents.goBack()
        }
    }
    goForward() {
        const tabIndex = this.tabs.findIndex(tab => tab.id === this.activeTabId)
        if (tabIndex !== -1) {
            const tab = this.tabs[tabIndex];
            if (tab.view.webContents.canGoForward())
                tab.view.webContents.goForward()
        }
    }
    setActiveTab(tabId) {
        const previousActiveTab = this.tabs.find(tab => tab.id === this.activeTabId)
        if (previousActiveTab) {
            previousActiveTab.view.setVisible(false)
        }
        const tab = this.tabs.find(tab => tab.id == tabId)
        if (tab) {
            tab.view.setVisible(true)
            this.activeTabId = tabId
            this.win.webContents.send('tab-activated', {
                id: tab.id,
                title: tab.title,
                url: tab.url,
                close: tab.close,
                isActive: tab.isActive
            })
        }
    }
    updateViewLayout() {
        const [windowWidth, windowHeight] = this.win.getContentSize();
        this.tabs.forEach(tab => {
            tab.view.setBounds({
                x: 0,
                y: this.tabHeight,
                width: windowWidth,
                height: windowHeight - this.tabHeight
            });
        });
    }
}
HomeService.toString = () => '[class HomeService]';

module.exports = {
    HomeService,
    homeService: new HomeService()
};